#include "stdio.h"
#include "stdlib.h"
#include "fvlib.h"

int main()
{
    uint8_t *image_buf;
    int32_t img_width, img_height, img_width_align;
    int32_t afwin_x, afwin_y, afwin_width, afwin_heigth;
    uint64t focus_value;
    FILE *fp = NULL;

    img_width = 656;
    img_height = 480;
    img_width_align = 656;
    afwin_x = 100;
    afwin_y = 100;
    afwin_width = 400;
    afwin_heigth = 300;

    image_buf = malloc(img_width_align * img_height * sizeof(uint8_t));
    if (!image_buf) {
        printf("get image buffer failed!\n");
        goto OUT;
    }

    fp = fopen("/data/af_demo.y", "rb");
    if (fp) {
        if (fread(image_buf, img_width_align * img_height * sizeof(uint8_t), 1, fp) != 1) {
            printf("read demo raw failed!\n");
            goto OUT;
        }

        getFocusValue(image_buf, img_width, img_height, img_width_align,
            afwin_x, afwin_y, afwin_width, afwin_heigth, &focus_value);
        printf("get focus value %llu\n", focus_value);
    }

OUT:
    if (fp)
        fclose(fp);
    if (image_buf)
        free(image_buf);

    return 0;
}